import { createRouter,createWebHashHistory } from "vue-router";
import { useStore } from "../store/user";

const routes=[
    {
        path:'/',
        name:'ListHome',
        component:() => import('../views/ListHome.vue')
    },
    {
        path:"/details/:id",
        name:"details",
        component:() => import('../components/Details.vue'),
        props:true
    }, 
    {
        path:'/create',
        name:'create',
        component:() => import('../components/Create.vue'),
    },
    {
        path:'/login',
        name:'login',
        component:() => import('../components/Login.vue'),
        props:true
    }
]


const router=createRouter({
    history:createWebHashHistory(),
    routes
})

router.beforeEach((to) => {
    const store = useStore()
    if(!store.token && to.path !== '/login'){
         return '/login'
    }
})


export default router;